package com.community.demo.controller;


import com.community.demo.domain.Blog;
import com.community.demo.domain.User;
import com.community.demo.service.IUserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class UserController {

    final int BLOGPOINTS = 3;
    private IUserService userService;

    @GetMapping("/usersList")
    public ModelAndView list() {
//        Iterable<User> users = this.userRepository.findAll();
        return new ModelAndView("users/list");

    }

    @GetMapping("/editBlog")
    public String toBlog(User user, Blog blog){
        user.getBlogs().add(blog);
        user.setPoints(user.getPoints()+BLOGPOINTS);
        userService.saveAndFlush(user);
        return "blog";
    }
}
